##### R CODE TO REPLICATE THE TABLES INCLUDED IN 
##### Adrian Lucardi, "Building Support from Below? Subnational Elections, Diffusion Effects, and the Growth of the Opposition in Mexico, 1984-2000," Comparative Political Studies, 49(14), 2016, 1855-1895.

## Loading the required R packages. Make sure to have them installed before proceeding. In order to install a package called X, write install.packages("X")
library (foreign)
library (lmtest)
library (MASS)
library (plm)
library (sandwich)
library (survival)
library (xtable)

## display options
options (digits=4, scipen=6, show.signif.stars=FALSE)

## working directory -> change this to the directory where your have your data
setwd ("/Users/adrianlucardi/Desktop/Replication/")


###### DOWNLOADING THE DATA

### Municipal elections
base <- read.dta ("Mexico Municipal elections 1984-2000.dta")
base$noWinner <- with (base, 1-(winPAN+winPRI+winPRD+winPAN_PRD+winOTH)) ## elections with no winner

# re-factorizing
base$muni <- factor (base$muni)
base$muniYear_lag <- factor (base$muniYear_lag)
base$election <- factor (base$election)
base$muniYear <- factor (base$muniYear)
base$state <- factor (base$state)
base$stateYear <- factor (base$stateYear)
base$source <- factor (base$source)
base$Winner <- factor (base$Winner)
base$Winner2 <- factor (base$Winner2)
base$Incumbent <- factor (base$Incumbent)
base$incGover <- factor (base$incGover)


## Creating some additional variables

## "Cycles" and "year" dummies. Note that the "cycle" variable indicates in what stage of the electoral calendar a state was in
base$cyc02 <- with (base, ifelse (cycle==2, 1, 0))
base$cyc03 <- with (base, ifelse (cycle==3, 1, 0))
base$cyc04 <- with (base, ifelse (cycle==4, 1, 0))
base$cyc05 <- with (base, ifelse (cycle==5, 1, 0))
base$cyc06 <- with (base, ifelse (cycle==6, 1, 0))
base$cyc07 <- with (base, ifelse (cycle==7, 1, 0))

base$y1984 <- with (base, ifelse (year==1984, 1, 0))
base$y1985 <- with (base, ifelse (year==1985, 1, 0))
base$y1986 <- with (base, ifelse (year==1986, 1, 0))
base$y1987 <- with (base, ifelse (year==1987, 1, 0))
base$y1988 <- with (base, ifelse (year==1988, 1, 0))
base$y1989 <- with (base, ifelse (year==1989, 1, 0))
base$y1990 <- with (base, ifelse (year==1990, 1, 0))
base$y1991 <- with (base, ifelse (year==1991, 1, 0))
base$y1992 <- with (base, ifelse (year==1992, 1, 0))
base$y1993 <- with (base, ifelse (year==1993, 1, 0))
base$y1994 <- with (base, ifelse (year==1994, 1, 0))
base$y1995 <- with (base, ifelse (year==1995, 1, 0))
base$y1996 <- with (base, ifelse (year==1996, 1, 0))
base$y1997 <- with (base, ifelse (year==1997, 1, 0))
base$y1998 <- with (base, ifelse (year==1998, 1, 0))
base$y1999 <- with (base, ifelse (year==1999, 1, 0))
base$y2000 <- with (base, ifelse (year==2000, 1, 0))

## Creating the PAN2 and PRD2 variables --> counting PAN-PRD alliances in favor of the PAN or PRD, respectivey
base$shPAN2 <- with (base, shPAN + shPAN_PRD)
base$firstPAN2 <- with (base, firstPAN + firstPAN_PRD)
base$winPAN2 <- with (base, winPAN + winPAN_PRD)
base$shPAN2_lag <- with (base, shPAN_lag + shPAN_PRD_lag)
base$incPAN2 <- with (base, incPAN + incPAN_PRD)
base$incPAN2_qrs <- with (base, incPAN_qrs + incPAN_PRD_qrs)
base$shPAN2_qrs <- with (base, shPAN_qrs + shPAN_PRD_qrs)

base$shPRD2 <- with (base, shPRD + shPAN_PRD)
base$firstPRD2 <- with (base, firstPRD + firstPAN_PRD)
base$winPRD2 <- with (base, winPRD + winPAN_PRD)
base$shPRD2_lag <- with (base, shPRD_lag + shPAN_PRD_lag)
base$incPRD2 <- with (base, incPRD + incPAN_PRD)
base$incPRD2_qrs <- with (base, incPRD_qrs + incPAN_PRD_qrs)
base$shPRD2_qrs <- with (base, shPRD_qrs + shPAN_PRD_qrs)


## Creating the .plm datasets

## (a) PAN datasets (1984-2000)

# main dataset
base.pan <- pdata.frame (base[base$noWinner==0,], index=c("muni", "cycle"))

# states where the opposition had never won
base.pan2 <- pdata.frame (base[base$alt==0 & base$noWinner==0,], index=c("muni", "cycle"))

# excluding Oaxaca
base.pan3 <- pdata.frame (base[base$state!="OAX" & base$noWinner==0,], index=c("muni", "cycle"))


## (b) PRD datasets (post-1989)

# main dataset
base.prd <- pdata.frame (base[base$year >= 1989 & base$noWinner==0,], index=c("muni", "cycle"))

# states where the opposition had never won
base.prd2 <- pdata.frame (base[base$year >= 1989 & base$alt==0 & base$noWinner==0,], index=c("muni", "cycle"))

# excluding Oaxaca
base.prd3 <- pdata.frame (base[base$year >= 1989 & base$state!="OAX" & base$noWinner==0,], index=c("muni", "cycle"))



### Federal elections
base.fed <- read.dta ("Mexico Federal elections 1991-2000.dta")
base.fed$noWinner <- with (base.fed, 1-(winPAN+winPRI+winPRD+winPAN_PRD+winOTH)) ## elections with no winner

# re-factorizing
base.fed$muniYearFed <- factor (base.fed$muniYearFed)
base.fed$muniYearFed_lag <- factor (base.fed$muniYearFed_lag)
base.fed$state <- factor (base.fed$state)
base.fed$stateYear <- factor (base.fed$stateYear)
base.fed$stateYearFed <- factor (base.fed$stateYearFed)
base.fed$muni <- factor (base.fed$muni)
base.fed$source <- factor (base.fed$source)
base.fed$Winner <- factor (base.fed$Winner)
base.fed$Winner2 <- factor (base.fed$Winner2)
base.fed$incGover <- factor (base.fed$incGover)


## Creating some additional variables

# Creating the "year" dummies
base.fed$yearsDif <- factor (base.fed$yearsDif) ## years since municipal election
base.fed$y1991 <- with (base.fed, ifelse (yearFedNext==1991, 1, 0))
base.fed$y1994 <- with (base.fed, ifelse (yearFedNext==1994, 1, 0))
base.fed$y1997 <- with (base.fed, ifelse (yearFedNext==1997, 1, 0))
base.fed$y2000 <- with (base.fed, ifelse (yearFedNext==2000, 1, 0))

# Creating the PAN2 and PRD2 variables --> for neighbors only, no PAN-PRD alliances in SMD elections
base.fed$incPAN2_qrs <- with (base.fed, incPAN_qrs + incPAN_PRD_qrs)
base.fed$shPAN2_qrs <- with (base.fed, shPAN_qrs + shPAN_PRD_qrs)
base.fed$incPRD2_qrs <- with (base.fed, incPRD_qrs + incPAN_PRD_qrs)
base.fed$shPRD2_qrs <- with (base.fed, shPRD_qrs + shPAN_PRD_qrs)

base.fed$incPAN2_nkrs <- with (base.fed, incPAN_nkrs + incPAN_PRD_nkrs)
base.fed$shPAN2_nkrs <- with (base.fed, shPAN_nkrs + shPAN_PRD_nkrs)
base.fed$incPRD2_nkrs <- with (base.fed, incPRD_nkrs + incPAN_PRD_nkrs)
base.fed$shPRD2_nkrs <- with (base.fed, shPRD_nkrs + shPAN_PRD_nkrs)

base.fed$incPAN2_smdrs <- with (base.fed, incPAN_smdrs + incPAN_PRD_smdrs)
base.fed$shPAN2_smdrs <- with (base.fed, shPAN_smdrs + shPAN_PRD_smdrs)
base.fed$incPRD2_smdrs <- with (base.fed, incPRD_smdrs + incPAN_PRD_smdrs)
base.fed$shPRD2_smdrs <- with (base.fed, shPRD_smdrs + shPAN_PRD_smdrs)


## Creating the .plm datasets

## (a) PAN datasets

# main dataset
base.fed.pan <- pdata.frame (base.fed[base.fed$noWinner==0,], index=c("muni", "yearFedNext"))

# states where the opposition had never won
base.fed.pan2 <- pdata.frame (base.fed[base.fed$alt_fed==0 & base.fed$noWinner==0,], index=c("muni", "yearFedNext"))

# excluding Oaxaca
base.fed.pan3 <- pdata.frame (base.fed[base.fed$state!="OAX" & base.fed$noWinner==0,], index=c("muni", "yearFedNext"))


## (b) PRD datasets

# main dataset
base.fed.prd <- pdata.frame (base.fed[base.fed$noWinner==0,], index=c("muni", "yearFedNext"))

# states where the opposition had never won
base.fed.prd2 <- pdata.frame (base.fed[base.fed$alt_fed==0 & base.fed$noWinner==0,], index=c("muni", "yearFedNext"))

# excluding Oaxaca
base.fed.prd3 <- pdata.frame (base.fed[base.fed$state!="OAX" & base.fed$noWinner==0,], index=c("muni", "yearFedNext"))




########## FITTING THE MODELS

### Replicating the models in Table 3

# model 1
(sum.Wpan.gov001a <- summary (Wpan.gov001a <- plm (winPAN ~ goverPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni")))) ## have to include years and cycles as dummies b/c plm gives an error otherwise
(coef.Wpan.gov001a <- coeftest (Wpan.gov001a, vcov=vcovHC (Wpan.gov001a, type="HC3", cluster="group")))  ## to get SEs clustered by municipality

# model 2
(sum.Wpan.qrs002a <- summary (Wpan.qrs002a <- plm (winPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs002a <- coeftest (Wpan.qrs002a, vcov=vcovHC (Wpan.qrs002a, type="HC3", cluster="group")))

# model 3
(sum.Wpan.qrs003a <- summary (Wpan.qrs003a <- plm (winPAN ~ incPAN_qrs + shPAN_qrs + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan2, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs003a <- coeftest (Wpan.qrs003a, vcov=vcovHC (Wpan.qrs003a, type="HC3", cluster="group")))

# model 4
(sum.Wprd.qrs002a <- summary (Wprd.qrs002a <- plm (winPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs002a <- coeftest (Wprd.qrs002a, vcov=vcovHC (Wprd.qrs002a, type="HC3", cluster="group")))

# model 5
(sum.Wprd.qrs003a <- summary (Wprd.qrs003a <- plm (winPRD ~ incPRD_qrs + shPRD_qrs + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd2, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs003a <- coeftest (Wprd.qrs003a, vcov=vcovHC (Wprd.qrs003a, type="HC3", cluster="group")))

# model 6
(sum.Vpan.gov001a <- summary (Vpan.gov001a <- plm (shPAN ~ goverPAN + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.gov001a <- coeftest (Vpan.gov001a, vcov=vcovHC (Vpan.gov001a, type="HC3", cluster="group")))

# model 7
(sum.Vpan.qrs002a <- summary (Vpan.qrs002a <- plm (shPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002a <- coeftest (Vpan.qrs002a, vcov=vcovHC (Vpan.qrs002a, type="HC3", cluster="group")))

# (excluding the shPAN_qrs variable from the specification)
(sum.Vpan.qrs002a2 <- summary (Vpan.qrs002a2 <- plm (shPAN ~ incPAN_qrs*alt + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002a2 <- coeftest (Vpan.qrs002a2, vcov=vcovHC (Vpan.qrs002a2, type="HC3", cluster="group")))

# model 8
(sum.Vpan.qrs003a <- summary (Vpan.qrs003a <- plm (shPAN ~ incPAN_qrs + shPAN_qrs + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan2, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs003a <- coeftest (Vpan.qrs003a, vcov=vcovHC (Vpan.qrs003a, type="HC3", cluster="group")))

# (excluding the shPAN_qrs variable from the specification)
(sum.Vpan.qrs003a2 <- summary (Vpan.qrs003a2 <- plm (shPAN ~ incPAN_qrs + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan2, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs003a2 <- coeftest (Vpan.qrs003a2, vcov=vcovHC (Vpan.qrs003a2, type="HC3", cluster="group")))

# model 9
(sum.Vprd.qrs002a <- summary (Vprd.qrs002a <- plm (shPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs002a <- coeftest (Vprd.qrs002a, vcov=vcovHC (Vprd.qrs002a, type="HC3", cluster="group")))

# model 10
(sum.Vprd.qrs003a <- summary (Vprd.qrs003a <- plm (shPRD ~ incPRD_qrs + shPRD_qrs + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd2, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs003a <- coeftest (Vprd.qrs003a, vcov=vcovHC (Vprd.qrs003a, type="HC3", cluster="group")))




### Replicating the models in Table 4

# model 1
(sum.Wpan.fed.gov001a <- summary (Wpan.fed.gov001a <- plm (firstPAN_fed ~ goverPAN + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.gov001a <- coeftest (Wpan.fed.gov001a, vcov=vcovHC (Wpan.fed.gov001a, type="HC3", cluster="group")))

# model 2
(sum.Wpan.fed.qrs002a <- summary (Wpan.fed.qrs002a <- plm (firstPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs002a <- coeftest (Wpan.fed.qrs002a, vcov=vcovHC (Wpan.fed.qrs002a, type="HC3", cluster="group")))

# model 3
(sum.Wpan.fed.qrs003a <- summary (Wpan.fed.qrs003a <- plm (firstPAN_fed ~ incPAN_qrs + shPAN_qrs + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan2, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs003a <- coeftest (Wpan.fed.qrs003a, vcov=vcovHC (Wpan.fed.qrs003a, type="HC3", cluster="group")))

# model 4
(sum.Wprd.fed.gov001a <- summary (Wprd.fed.gov001a <- plm (firstPRD_fed ~ goverPRD + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.gov001a <- coeftest (Wprd.fed.gov001a, vcov=vcovHC (Wprd.fed.gov001a, type="HC3", cluster="group")))

# model 5
(sum.Wprd.fed.qrs002a <- summary (Wprd.fed.qrs002a <- plm (firstPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs002a <- coeftest (Wprd.fed.qrs002a, vcov=vcovHC (Wprd.fed.qrs002a, type="HC3", cluster="group")))

# model 6
(sum.Wprd.fed.qrs003a <- summary (Wprd.fed.qrs003a <- plm (firstPRD_fed ~ incPRD_qrs + shPRD_qrs + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd2, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs003a <- coeftest (Wprd.fed.qrs003a, vcov=vcovHC (Wprd.fed.qrs003a, type="HC3", cluster="group")))

# model 7
(sum.Vpan.fed.gov001a <- summary (Vpan.fed.gov001a <- plm (shPAN_fed ~ goverPAN + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.gov001a <- coeftest (Vpan.fed.gov001a, vcov=vcovHC (Vpan.fed.gov001a, type="HC3", cluster="group")))

# model 8
(sum.Vpan.fed.qrs002a <- summary (Vpan.fed.qrs002a <- plm (shPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs002a <- coeftest (Vpan.fed.qrs002a, vcov=vcovHC (Vpan.fed.qrs002a, type="HC3", cluster="group")))

# model 9
(sum.Vpan.fed.qrs003a <- summary (Vpan.fed.qrs003a <- plm (shPAN_fed ~ incPAN_qrs + shPAN_qrs + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan2, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs003a <- coeftest (Vpan.fed.qrs003a, vcov=vcovHC (Vpan.fed.qrs003a, type="HC3", cluster="group")))

# model 10
(sum.Vprd.fed.gov001a <- summary (Vprd.fed.gov001a <- plm (shPRD_fed ~ goverPRD + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.gov001a <- coeftest (Vprd.fed.gov001a, vcov=vcovHC (Vprd.fed.gov001a, type="HC3", cluster="group")))

# model 11
(sum.Vprd.fed.qrs002a <- summary (Vprd.fed.qrs002a <- plm (shPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs002a <- coeftest (Vprd.fed.qrs002a, vcov=vcovHC (Vprd.fed.qrs002a, type="HC3", cluster="group")))

# model 12
(sum.Vprd.fed.qrs003a <- summary (Vprd.fed.qrs003a <- plm (shPRD_fed ~ incPRD_qrs + shPRD_qrs + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd2, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs003a <- coeftest (Vprd.fed.qrs003a, vcov=vcovHC (Vprd.fed.qrs003a, type="HC3", cluster="group")))



### Replicating the models in Table A1

## Panel (a)

# model 2.1
(sum.Wpan.gov001b <- summary (Wpan.gov001b <- plm (winPAN ~ goverPAN + shPAN_lag + concGober + split + poverty + rural + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.gov001b <- coeftest (Wpan.gov001b, vcov=vcovHC (Wpan.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Wpan.gov001e <- summary (Wpan.gov001e <- plm (winPAN ~ goverPAN + incPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Wpan.gov001e <- coeftest (Wpan.gov001e, vcov=vcovHC (Wpan.gov001e, type="HC3", cluster="group")))

# model 7.1
(sum.Wpan.gov001f <- summary (Wpan.gov001f <- plm (winPAN2 ~ goverPAN + shPAN2_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.gov001f <- coeftest (Wpan.gov001f, vcov=vcovHC (Wpan.gov001f, type="HC3", cluster="group")))

# model 8.1
(sum.Wpan.gov001g <- summary (Wpan.gov001g <- plm (winPAN ~ goverPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.gov001g <- coeftest (Wpan.gov001g, vcov=vcovHC (Wpan.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Wpan.qrs002b <- summary (Wpan.qrs002b <- plm (winPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + shPAN_lag + concGober + split + poverty + rural + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs002b <- coeftest (Wpan.qrs002b, vcov=vcovHC (Wpan.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Wpan.nkrs002a <- summary (Wpan.nkrs002a <- plm (winPAN ~ incPAN_nkrs*alt + shPAN_nkrs*alt + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.nkrs002a <- coeftest (Wpan.nkrs002a, vcov=vcovHC (Wpan.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Wpan.smdrs002h <- summary (Wpan.smdrs002h <- plm (winPAN ~ incPAN_smdrs*alt + shPAN_smdrs*alt + shPAN_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.smdrs002h <- coeftest (Wpan.smdrs002h, vcov=vcovHC (Wpan.smdrs002h, type="HC3", cluster="group")))

# model 5.2
(sum.Wpan.qrs002c <- summary (Wpan.qrs002c <- plm (winPAN ~ incPAN_qdum*alt + shPAN_qrs*alt + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs002c <- coeftest (Wpan.qrs002c, vcov=vcovHC (Wpan.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Wpan.qrs002e <- summary (Wpan.qrs002e <- plm (winPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + incPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Wpan.qrs002e <- coeftest (Wpan.qrs002e, vcov=vcovHC (Wpan.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Wpan.qrs002f <-  summary (Wpan.qrs002f <-  plm (winPAN2 ~ incPAN2_qrs*alt + shPAN2_qrs*alt + shPAN2_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs002f <-  coeftest (Wpan.qrs002f, vcov=vcovHC (Wpan.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Wpan.qrs002g <- summary (Wpan.qrs002g <- plm (winPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.qrs002g <- coeftest (Wpan.qrs002g, vcov=vcovHC (Wpan.qrs002g, type="HC3", cluster="group")))


## Panel (b)

# model 2.1
(sum.Vpan.gov001b <- summary (Vpan.gov001b <- plm (shPAN ~ goverPAN + incPAN + concGober + split + poverty + rural + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.gov001b <- coeftest (Vpan.gov001b, vcov=vcovHC (Vpan.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Vpan.gov001e <- summary (Vpan.gov001e <- plm (shPAN ~ goverPAN + incPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Vpan.gov001e <- coeftest (Vpan.gov001e, vcov=vcovHC (Vpan.gov001e, type="HC3", cluster="group")))

# model 7.1
(sum.Vpan.gov001f <- summary (Vpan.gov001f <- plm (shPAN2 ~ goverPAN + incPAN2 + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.gov001f <- coeftest (Vpan.gov001f, vcov=vcovHC (Vpan.gov001f, type="HC3", cluster="group")))

# model 8.1
(sum.Vpan.gov001g <- summary (Vpan.gov001g <- plm (shPAN ~ goverPAN + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.gov001g <- coeftest (Vpan.gov001g, vcov=vcovHC (Vpan.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Vpan.qrs002b <- summary (Vpan.qrs002b <- plm (shPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + incPAN + concGober + split + poverty + rural + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002b <- coeftest (Vpan.qrs002b, vcov=vcovHC (Vpan.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Vpan.nkrs002a <- summary (Vpan.nkrs002a <- plm (shPAN ~ incPAN_nkrs*alt + shPAN_nkrs*alt + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.nkrs002a <- coeftest (Vpan.nkrs002a, vcov=vcovHC (Vpan.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Vpan.smdrs002h <- summary (Vpan.smdrs002h <- plm (shPAN ~ incPAN_smdrs*alt + shPAN_smdrs*alt + incPAN + concGober + split + cyc05 + cyc06 + cyc07 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.smdrs002h <- coeftest (Vpan.smdrs002h, vcov=vcovHC (Vpan.smdrs002h, type="HC3", cluster="group")))

# model 5.2
(sum.Vpan.qrs002c <- summary (Vpan.qrs002c <- plm (shPAN ~ incPAN_qdum*alt + shPAN_qrs*alt + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002c <- coeftest (Vpan.qrs002c, vcov=vcovHC (Vpan.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Vpan.qrs002e <- summary (Vpan.qrs002e <- plm (shPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + incPAN + shPAN_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Vpan.qrs002e <- coeftest (Vpan.qrs002e, vcov=vcovHC (Vpan.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Vpan.qrs002f <-  summary (Vpan.qrs002f <-  plm (shPAN2 ~ incPAN2_qrs*alt + shPAN2_qrs*alt + shPAN2_lag + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002f <-  coeftest (Vpan.qrs002f, vcov=vcovHC (Vpan.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Vpan.qrs002g <- summary (Vpan.qrs002g <- plm (shPAN ~ incPAN_qrs*alt + shPAN_qrs*alt + incPAN + concGober + split + cyc03 + cyc04 + cyc05 + cyc06 + cyc07 + y1985 + y1986 + y1987 + y1989 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.qrs002g <- coeftest (Vpan.qrs002g, vcov=vcovHC (Vpan.qrs002g, type="HC3", cluster="group")))


## Panel (c)

# model 2
(sum.Wprd.qrs002b <- summary (Wprd.qrs002b <- plm (winPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + shPRD_lag + concGober + split + poverty + rural + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs002b <- coeftest (Wprd.qrs002b, vcov=vcovHC (Wprd.qrs002b, type="HC3", cluster="group")))

# model 3
(sum.Wprd.nkrs002a <- summary (Wprd.nkrs002a <- plm (winPRD ~ incPRD_nkrs*alt + shPRD_nkrs*alt + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.nkrs002a <- coeftest (Wprd.nkrs002a, vcov=vcovHC (Wprd.nkrs002a, type="HC3", cluster="group")))

# model 4
(sum.Wprd.smdrs002h <- summary (Wprd.smdrs002h <- plm (winPRD ~ incPRD_smdrs*alt + shPRD_smdrs*alt + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.smdrs002h <- coeftest (Wprd.smdrs002h, vcov=vcovHC (Wprd.smdrs002h, type="HC3", cluster="group")))

# model 5
(sum.Wprd.qrs002c <- summary (Wprd.qrs002c <- plm (winPRD ~ incPRD_qdum*alt + shPRD_qrs*alt + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs002c <- coeftest (Wprd.qrs002c, vcov=vcovHC (Wprd.qrs002c, type="HC3", cluster="group")))

# model 6
(sum.Wprd.qrs002e <- summary (Wprd.qrs002e <- plm (winPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + incPRD + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Wprd.qrs002e <- coeftest (Wprd.qrs002e, vcov=vcovHC (Wprd.qrs002e, type="HC3", cluster="group")))

# model 7
(sum.Wprd.qrs002f <-  summary (Wprd.qrs002f <-  plm (winPRD2 ~ incPRD2_qrs*alt + shPRD2_qrs*alt + shPRD2_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs002f <-  coeftest (Wprd.qrs002f, vcov=vcovHC (Wprd.qrs002f, type="HC3", cluster="group")))

# model 8
(sum.Wprd.qrs002g <- summary (Wprd.qrs002g <- plm (winPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.qrs002g <- coeftest (Wprd.qrs002g, vcov=vcovHC (Wprd.qrs002g, type="HC3", cluster="group")))


## Panel (d)

# model 2
(sum.Vprd.qrs002b <- summary (Vprd.qrs002b <- plm (shPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + incPRD + concGober + split + poverty + rural + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs002b <- coeftest (Vprd.qrs002b, vcov=vcovHC (Vprd.qrs002b, type="HC3", cluster="group")))

# model 3
(sum.Vprd.nkrs002a <- summary (Vprd.nkrs002a <- plm (shPRD ~ incPRD_nkrs*alt + shPRD_nkrs*alt + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.nkrs002a <- coeftest (Vprd.nkrs002a, vcov=vcovHC (Vprd.nkrs002a, type="HC3", cluster="group")))

# model 4
(sum.Vprd.smdrs002h <- summary (Vprd.smdrs002h <- plm (shPRD ~ incPRD_smdrs*alt + shPRD_smdrs*alt + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.smdrs002h <- coeftest (Vprd.smdrs002h, vcov=vcovHC (Vprd.smdrs002h, type="HC3", cluster="group")))

# model 5
(sum.Vprd.qrs002c <- summary (Vprd.qrs002c <- plm (shPRD ~ incPRD_qdum*alt + shPRD_qrs*alt + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs002c <- coeftest (Vprd.qrs002c, vcov=vcovHC (Vprd.qrs002c, type="HC3", cluster="group")))

# model 6
(sum.Vprd.qrs002e <- summary (Vprd.qrs002e <- plm (shPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + incPRD + shPRD_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Vprd.qrs002e <- coeftest (Vprd.qrs002e, vcov=vcovHC (Vprd.qrs002e, type="HC3", cluster="group")))

# model 7
(sum.Vprd.qrs002f <-  summary (Vprd.qrs002f <-  plm (shPRD2 ~ incPRD2_qrs*alt + shPRD2_qrs*alt + shPRD2_lag + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs002f <-  coeftest (Vprd.qrs002f, vcov=vcovHC (Vprd.qrs002f, type="HC3", cluster="group")))

# model 8
(sum.Vprd.qrs002g <- summary (Vprd.qrs002g <- plm (shPRD ~ incPRD_qrs*alt + shPRD_qrs*alt + incPRD + concGober + split + cyc05 + cyc06 + cyc07 + y1990 + y1991 + y1992 + y1993 + y1994 + y1995 + y1996 + y1997 + y1998 + y1999, data=base.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.qrs002g <- coeftest (Vprd.qrs002g, vcov=vcovHC (Vprd.qrs002g, type="HC3", cluster="group")))




### Replicating the models in Table A2

## Panel (a)

# model 2.1
(sum.Wpan.fed.gov001b <- summary (Wpan.fed.gov001b <- plm (firstPAN_fed ~ goverPAN + shPAN_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.gov001b <- coeftest (Wpan.fed.gov001b, vcov=vcovHC (Wpan.fed.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Wpan.fed.gov001e <- summary (Wpan.fed.gov001e <- plm (firstPAN_fed ~ goverPAN + firstPAN_fed_lag + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Wpan.fed.gov001e <- coeftest (Wpan.fed.gov001e, vcov=vcovHC (Wpan.fed.gov001e, type="HC3", cluster="group")))

# model 8.1
(sum.Wpan.fed.gov001g <- summary (Wpan.fed.gov001g <- plm (firstPAN_fed ~ goverPAN + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.gov001g <- coeftest (Wpan.fed.gov001g, vcov=vcovHC (Wpan.fed.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Wpan.fed.qrs002b <- summary (Wpan.fed.qrs002b <- plm (firstPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + shPAN_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs002b <- coeftest (Wpan.fed.qrs002b, vcov=vcovHC (Wpan.fed.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Wpan.fed.nkrs002a <- summary (Wpan.fed.nkrs002a <- plm (firstPAN_fed ~ incPAN_nkrs*alt_fed + shPAN_nkrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.nkrs002a <- coeftest (Wpan.fed.nkrs002a, vcov=vcovHC (Wpan.fed.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Wpan.fed.smdrs002a <- summary (Wpan.fed.smdrs002a <- plm (firstPAN_fed ~ incPAN_smdrs*alt_fed + shPAN_smdrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.smdrs002a <- coeftest (Wpan.fed.smdrs002a, vcov=vcovHC (Wpan.fed.smdrs002a, type="HC3", cluster="group")))

# model 5.2
(sum.Wpan.fed.qrs002c <- summary (Wpan.fed.qrs002c <- plm (firstPAN_fed ~ incPAN_qdum*alt_fed + shPAN_qrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs002c <- coeftest (Wpan.fed.qrs002c, vcov=vcovHC (Wpan.fed.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Wpan.fed.qrs002e <- summary (Wpan.fed.qrs002e <- plm (firstPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Wpan.fed.qrs002e <- coeftest (Wpan.fed.qrs002e, vcov=vcovHC (Wpan.fed.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Wpan.fed.qrs002f <-  summary (Wpan.fed.qrs002f <-  plm (firstPAN_fed ~ incPAN2_qrs*alt_fed + shPAN2_qrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs002f <-  coeftest (Wpan.fed.qrs002f, vcov=vcovHC (Wpan.fed.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Wpan.fed.qrs002g <- summary (Wpan.fed.qrs002g <- plm (firstPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Wpan.fed.qrs002g <- coeftest (Wpan.fed.qrs002g, vcov=vcovHC (Wpan.fed.qrs002g, type="HC3", cluster="group")))


## Panel (b)

# model 2.1
(sum.Vpan.fed.gov001b <- summary (Vpan.fed.gov001b <- plm (shPAN_fed ~ goverPAN + firstPAN_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.gov001b <- coeftest (Vpan.fed.gov001b, vcov=vcovHC (Vpan.fed.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Vpan.fed.gov001e <- summary (Vpan.fed.gov001e <- plm (shPAN_fed ~ goverPAN + shPAN_fed_lag + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Vpan.fed.gov001e <- coeftest (Vpan.fed.gov001e, vcov=vcovHC (Vpan.fed.gov001e, type="HC3", cluster="group")))

# model 8.1
(sum.Vpan.fed.gov001g <- summary (Vpan.fed.gov001g <- plm (shPAN_fed ~ goverPAN + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.gov001g <- coeftest (Vpan.fed.gov001g, vcov=vcovHC (Vpan.fed.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Vpan.fed.qrs002b <- summary (Vpan.fed.qrs002b <- plm (shPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs002b <- coeftest (Vpan.fed.qrs002b, vcov=vcovHC (Vpan.fed.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Vpan.fed.nkrs002a <- summary (Vpan.fed.nkrs002a <- plm (shPAN_fed ~ incPAN_nkrs*alt_fed + shPAN_nkrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.nkrs002a <- coeftest (Vpan.fed.nkrs002a, vcov=vcovHC (Vpan.fed.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Vpan.fed.smdrs002a <- summary (Vpan.fed.smdrs002a <- plm (shPAN_fed ~ incPAN_smdrs*alt_fed + shPAN_smdrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.smdrs002a <- coeftest (Vpan.fed.smdrs002a, vcov=vcovHC (Vpan.fed.smdrs002a, type="HC3", cluster="group")))

# model 5.2
(sum.Vpan.fed.qrs002c <- summary (Vpan.fed.qrs002c <- plm (shPAN_fed ~ incPAN_qdum*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs002c <- coeftest (Vpan.fed.qrs002c, vcov=vcovHC (Vpan.fed.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Vpan.fed.qrs002e <- summary (Vpan.fed.qrs002e <- plm (shPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + shPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="pooling", index=c("muni"))))
(coef.Vpan.fed.qrs002e <- coeftest (Vpan.fed.qrs002e, vcov=vcovHC (Vpan.fed.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Vpan.fed.qrs002f <-  summary (Vpan.fed.qrs002f <-  plm (shPAN_fed ~ incPAN2_qrs*alt_fed + shPAN2_qrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs002f <-  coeftest (Vpan.fed.qrs002f, vcov=vcovHC (Vpan.fed.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Vpan.fed.qrs002g <- summary (Vpan.fed.qrs002g <- plm (shPAN_fed ~ incPAN_qrs*alt_fed + shPAN_qrs*alt_fed + firstPAN_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.pan3, effect="individual", model="within", index=c("muni"))))
(coef.Vpan.fed.qrs002g <- coeftest (Vpan.fed.qrs002g, vcov=vcovHC (Vpan.fed.qrs002g, type="HC3", cluster="group")))



## Panel (c)

# model 2.1
(sum.Wprd.fed.gov001b <- summary (Wprd.fed.gov001b <- plm (firstPRD_fed ~ goverPRD + shPRD_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.gov001b <- coeftest (Wprd.fed.gov001b, vcov=vcovHC (Wprd.fed.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Wprd.fed.gov001e <- summary (Wprd.fed.gov001e <- plm (firstPRD_fed ~ goverPRD + firstPRD_fed_lag + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Wprd.fed.gov001e <- coeftest (Wprd.fed.gov001e, vcov=vcovHC (Wprd.fed.gov001e, type="HC3", cluster="group")))

# model 8.1
(sum.Wprd.fed.gov001g <- summary (Wprd.fed.gov001g <- plm (firstPRD_fed ~ goverPRD + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.gov001g <- coeftest (Wprd.fed.gov001g, vcov=vcovHC (Wprd.fed.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Wprd.fed.qrs002b <- summary (Wprd.fed.qrs002b <- plm (firstPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + shPRD_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs002b <- coeftest (Wprd.fed.qrs002b, vcov=vcovHC (Wprd.fed.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Wprd.fed.nkrs002a <- summary (Wprd.fed.nkrs002a <- plm (firstPRD_fed ~ incPRD_nkrs*alt_fed + shPRD_nkrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.nkrs002a <- coeftest (Wprd.fed.nkrs002a, vcov=vcovHC (Wprd.fed.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Wprd.fed.smdrs002a <- summary (Wprd.fed.smdrs002a <- plm (firstPRD_fed ~ incPRD_smdrs*alt_fed + shPRD_smdrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.smdrs002a <- coeftest (Wprd.fed.smdrs002a, vcov=vcovHC (Wprd.fed.smdrs002a, type="HC3", cluster="group")))

# model 5.2
(sum.Wprd.fed.qrs002c <- summary (Wprd.fed.qrs002c <- plm (firstPRD_fed ~ incPRD_qdum*alt_fed + shPRD_qrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs002c <- coeftest (Wprd.fed.qrs002c, vcov=vcovHC (Wprd.fed.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Wprd.fed.qrs002e <- summary (Wprd.fed.qrs002e <- plm (firstPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Wprd.fed.qrs002e <- coeftest (Wprd.fed.qrs002e, vcov=vcovHC (Wprd.fed.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Wprd.fed.qrs002f <-  summary (Wprd.fed.qrs002f <-  plm (firstPRD_fed ~ incPRD2_qrs*alt_fed + shPRD2_qrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs002f <-  coeftest (Wprd.fed.qrs002f, vcov=vcovHC (Wprd.fed.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Wprd.fed.qrs002g <- summary (Wprd.fed.qrs002g <- plm (firstPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Wprd.fed.qrs002g <- coeftest (Wprd.fed.qrs002g, vcov=vcovHC (Wprd.fed.qrs002g, type="HC3", cluster="group")))


## Panel (d)

# model 2.1
(sum.Vprd.fed.gov001b <- summary (Vprd.fed.gov001b <- plm (shPRD_fed ~ goverPRD + firstPRD_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.gov001b <- coeftest (Vprd.fed.gov001b, vcov=vcovHC (Vprd.fed.gov001b, type="HC3", cluster="group")))

# model 6.1
(sum.Vprd.fed.gov001e <- summary (Vprd.fed.gov001e <- plm (shPRD_fed ~ goverPRD + shPRD_fed_lag + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Vprd.fed.gov001e <- coeftest (Vprd.fed.gov001e, vcov=vcovHC (Vprd.fed.gov001e, type="HC3", cluster="group")))

# model 8.1
(sum.Vprd.fed.gov001g <- summary (Vprd.fed.gov001g <- plm (shPRD_fed ~ goverPRD + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.gov001g <- coeftest (Vprd.fed.gov001g, vcov=vcovHC (Vprd.fed.gov001g, type="HC3", cluster="group")))

# model 2.2
(sum.Vprd.fed.qrs002b <- summary (Vprd.fed.qrs002b <- plm (shPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + poverty_fed + rural_fed + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs002b <- coeftest (Vprd.fed.qrs002b, vcov=vcovHC (Vprd.fed.qrs002b, type="HC3", cluster="group")))

# model 3.2
(sum.Vprd.fed.nkrs002a <- summary (Vprd.fed.nkrs002a <- plm (shPRD_fed ~ incPRD_nkrs*alt_fed + shPRD_nkrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.nkrs002a <- coeftest (Vprd.fed.nkrs002a, vcov=vcovHC (Vprd.fed.nkrs002a, type="HC3", cluster="group")))

# model 4.2
(sum.Vprd.fed.smdrs002a <- summary (Vprd.fed.smdrs002a <- plm (shPRD_fed ~ incPRD_smdrs*alt_fed + shPRD_smdrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.smdrs002a <- coeftest (Vprd.fed.smdrs002a, vcov=vcovHC (Vprd.fed.smdrs002a, type="HC3", cluster="group")))

# model 5.2
(sum.Vprd.fed.qrs002c <- summary (Vprd.fed.qrs002c <- plm (shPRD_fed ~ incPRD_qdum*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs002c <- coeftest (Vprd.fed.qrs002c, vcov=vcovHC (Vprd.fed.qrs002c, type="HC3", cluster="group")))

# model 6.2
(sum.Vprd.fed.qrs002e <- summary (Vprd.fed.qrs002e <- plm (shPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + shPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="pooling", index=c("muni"))))
(coef.Vprd.fed.qrs002e <- coeftest (Vprd.fed.qrs002e, vcov=vcovHC (Vprd.fed.qrs002e, type="HC3", cluster="group")))

# model 7.2
(sum.Vprd.fed.qrs002f <-  summary (Vprd.fed.qrs002f <-  plm (shPRD_fed ~ incPRD2_qrs*alt_fed + shPRD2_qrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs002f <-  coeftest (Vprd.fed.qrs002f, vcov=vcovHC (Vprd.fed.qrs002f, type="HC3", cluster="group")))

# model 8.2
(sum.Vprd.fed.qrs002g <- summary (Vprd.fed.qrs002g <- plm (shPRD_fed ~ incPRD_qrs*alt_fed + shPRD_qrs*alt_fed + firstPRD_fed_lag + concGober_fed + split + y1997 + y2000 + factor (yearsDif), data=base.fed.prd3, effect="individual", model="within", index=c("muni"))))
(coef.Vprd.fed.qrs002g <- coeftest (Vprd.fed.qrs002g, vcov=vcovHC (Vprd.fed.qrs002g, type="HC3", cluster="group")))





########## GAUGING THE MAGNITUDE OF THE EFFECTS

### (1) Municipal elections

## (a) PAN
round (mean (base.pan$winPAN), 3)  ## 7.4pp
round (mean (base.pan$incPAN_qrs), 3); round (sd (base.pan$incPAN_qrs), 3)  ## 5.3%; 13.0%
round (mean (base.pan[base.pan$incPAN_qrs>0,]$incPAN_qrs), 3); round (sd (base.pan[base.pan$incPAN_qrs>0,]$incPAN_qrs), 3)  ## municipalities with at least one neighbor: 27.4% and 16.5%

# marginal effects (Winner)
coef.Wpan.qrs002a[1,1] * sd (base.pan$incPAN_qrs)
coef.Wpan.qrs003a[1,1] * sd (base.pan$incPAN_qrs)
coef.Wpan.qrs002a[1,1] * sd (base.pan[base.pan$incPAN_qrs>0,]$incPAN_qrs) ## municipalities with at least one neighbor
coef.Wpan.qrs003a[1,1] * sd (base.pan[base.pan$incPAN_qrs>0,]$incPAN_qrs)

# proportional increase (Winner)
((coef.Wpan.qrs002a[1,1] * sd (base.pan$incPAN_qrs)) / mean (base.pan$winPAN)) * 100
((coef.Wpan.qrs003a[1,1] * sd (base.pan$incPAN_qrs)) / mean (base.pan$winPAN)) * 100

# marginal effects (Vote share)
coef.Vpan.qrs002a[1,1] * sd (base.pan$incPAN_qrs)
coef.Vpan.qrs003a[1,1] * sd (base.pan$incPAN_qrs)

# proportional increase (Vote share)
((coef.Vpan.qrs002a[1,1] * sd (base.pan$incPAN_qrs)) / mean (base.pan$shPAN)) * 100
((coef.Vpan.qrs003a[1,1] * sd (base.pan$incPAN_qrs)) / mean (base.pan$shPAN)) * 100

## Effect in states with alternation
vcov.Wpan.qrs002a <- vcovHC (Wpan.qrs002a, type="HC3", cluster="group")
z <- 1  ## alternation dummy

coef.Wpan.qrs002a[1,1] + coef.Wpan.qrs002a[26,1]  ## marginal effect is -0.013
(coef.Wpan.qrs002a[1,1] + coef.Wpan.qrs002a[26,1]) * sd (base.pan$incPAN_qrs) ## marginal effect is -0.16 percentage points
sqrt (vcov.Wpan.qrs002a[1,1] + z^2*vcov.Wpan.qrs002a[26,26] + 2*z*vcov.Wpan.qrs002a[26,1]) ## SE is 0.11


## (b) PRD
round (mean (base.pan[base.pan$year >= 1989,]$winPRD), 3)  ## 8.4pp.
round (mean (base.pan[base.pan$year >= 1989,]$incPRD_qrs), 3); round (sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs), 3)  ## 5.7%; 14.1%

# marginal effects (Winner)
coef.Wprd.qrs002a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)
coef.Wprd.qrs003a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)

# proportional increase (Winner)
((coef.Wprd.qrs002a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)) / mean (base.pan[base.pan$year >= 1989,]$winPRD)) * 100
((coef.Wprd.qrs003a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)) / mean (base.pan[base.pan$year >= 1989,]$winPRD)) * 100

# marginal effects (Vote share)
coef.Vprd.qrs002a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)
coef.Vprd.qrs003a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)

# proportional increase (Vote share)
((coef.Vprd.qrs002a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)) / mean (base.pan[base.pan$year >= 1989,]$shPRD)) * 100
((coef.Vprd.qrs003a[1,1] * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs)) / mean (base.pan[base.pan$year >= 1989,]$shPRD)) * 100

## Effect in states that experienced alternation

# winner
vcov.Wprd.qrs002a <- vcovHC (Wprd.qrs002a, type="HC3", cluster="group")
z <- 1  ## alternation dummy

coef.Wprd.qrs002a[1,1] + coef.Wprd.qrs002a[20,1]  ## marginal effect is 0.043
sqrt (vcov.Wprd.qrs002a[1,1] + z^2*vcov.Wprd.qrs002a[20,20] + 2*z*vcov.Wprd.qrs002a[20,1]) ## SE is 0.12
(coef.Wprd.qrs002a[1,1] + coef.Wprd.qrs002a[20,1]) * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs) ## marginal effect is 0.01 percentage points

# vote share
vcov.Vprd.qrs002a <- vcovHC (Vprd.qrs002a, type="HC3", cluster="group")
z <- 1  ## alternation dummy

coef.Vprd.qrs002a[1,1] + coef.Vprd.qrs002a[20,1]  ## marginal effect is 0.125
sqrt (vcov.Vprd.qrs002a[1,1] + z^2*vcov.Vprd.qrs002a[20,20] + 2*z*vcov.Vprd.qrs002a[20,1]) ## SE is 0.06
(coef.Vprd.qrs002a[1,1] + coef.Vprd.qrs002a[20,1]) * sd (base.pan[base.pan$year >= 1989,]$incPRD_qrs) ## marginal effect is 1.8 percentage points



### (2) Federal elections

## (a) PAN
round (mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPAN_fed), 3)  ## 8.8pp
round (mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs), 3); round (sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs), 3)  ## 9.9%; 16.9%

# marginal effects (Winner)
coef.Wpan.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)
coef.Wpan.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)

# proportional increase (Winner)
((coef.Wpan.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPAN_fed)) * 100
((coef.Wpan.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPAN_fed)) * 100

# marginal effects (Vote share)
coef.Vpan.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)
coef.Vpan.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)

# proportional increase (Vote share)
((coef.Vpan.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$shPAN_fed)) * 100
((coef.Vpan.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPAN_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$shPAN_fed)) * 100


## (b) PRD
round (mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPRD_fed), 3)  ## 7.1pp.
round (mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs), 3); round (sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs), 3)  ## 8.0%; 15.1%

# marginal effects (Winner)
coef.Wprd.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)
coef.Wprd.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)

# proportional increase (Winner)
((coef.Wprd.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPRD_fed)) * 100
((coef.Wprd.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$firstPRD_fed)) * 100

# marginal effects (Vote share)
coef.Vprd.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)
coef.Vprd.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)

# proportional increase (Vote share)
((coef.Vprd.fed.qrs002a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$shPRD_fed)) * 100
((coef.Vprd.fed.qrs003a[1,1] * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs)) / mean (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$shPRD_fed)) * 100


## Effect in states that experienced alternation

# winner
vcov.Wprd.fed.qrs002a <- vcovHC (Wprd.fed.qrs002a, type="HC3", cluster="group")
z <- 1  ## alternation dummy

coef.Wprd.fed.qrs002a[1,1] + coef.Wprd.fed.qrs002a[11,1]  ## marginal effect is 0.33
sqrt (vcov.Wprd.fed.qrs002a[1,1] + z^2*vcov.Wprd.fed.qrs002a[11,11] + 2*z*vcov.Wprd.fed.qrs002a[11,1]) ## SE is 0.14
(coef.Wprd.fed.qrs002a[1,1] + coef.Wprd.fed.qrs002a[11,1]) * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs) ## marginal effect is 5 percentage points

# vote share
vcov.Vprd.fed.qrs002a <- vcovHC (Vprd.fed.qrs002a, type="HC3", cluster="group")
z <- 1  ## alternation dummy

coef.Vprd.fed.qrs002a[1,1] + coef.Vprd.fed.qrs002a[11,1]  ## marginal effect is 0.10
sqrt (vcov.Vprd.fed.qrs002a[1,1] + z^2*vcov.Vprd.fed.qrs002a[11,11] + 2*z*vcov.Vprd.fed.qrs002a[11,1]) ## SE is 0.036
(coef.Vprd.fed.qrs002a[1,1] + coef.Vprd.fed.qrs002a[11,1]) * sd (base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,]$incPRD_qrs) ## marginal effect is 1.5 percentage points





########## BUILDING THE TABLES

### Replicating Table 2

## Municipal elections
base.desc <- base[base$noWinner==0,]
base.desc$state <- factor (base.desc$state)
base.desc$stateYear <- factor (base.desc$stateYear)
base.desc$muni <- factor (base.desc$muni)
base.desc$muniYear <- factor (base.desc$muniYear)
summary (base.desc); dim (base.desc)

# PRD: post-1988 elections only
base.desc$winPRD <- with (base.desc, ifelse (year <= 1988, NA, winPRD))
base.desc$shPRD <- with (base.desc, ifelse (year <= 1988, NA, shPRD))
base.desc$incPRD_qrs <- with (base.desc, ifelse (year <= 1988, NA, incPRD_qrs))
base.desc$incPRD <- with (base.desc, ifelse (year <= 1988, NA, incPRD))
base.desc$shPRD_lag <- with (base.desc, ifelse (year <= 1988, NA, shPRD_lag))
base.desc$shPRD_qrs <- with (base.desc, ifelse (year <= 1988, NA, shPRD_qrs))
base.desc$alt <- with (base.desc, ifelse (year <= 1988, NA, alt))
base.desc$concGober <- with (base.desc, ifelse (year <= 1988, NA, concGober))
base.desc$split <- with (base.desc, ifelse (year <= 1988, NA, split))
base.desc$poverty <- with (base.desc, ifelse (year <= 1988, NA, poverty))
base.desc$rural <- with (base.desc, ifelse (year <= 1988, NA, rural))


## Federal elections
base.desc.fed <- base.fed[base.fed$noWinner==0 & base.fed$yearFedNext>=1994,] ## because 1991 election not included in the analysis
base.desc.fed$muni <- factor (base.desc.fed$muni)
base.desc.fed$muniYearFed_lag <- factor (base.desc.fed$muniYearFed_lag)
base.desc.fed$muniYearFed <- factor (base.desc.fed$muniYearFed)
base.desc.fed$stateYear <- factor (base.desc.fed$stateYear)
base.desc.fed$state <- factor (base.desc.fed$state)
base.desc.fed$source <- factor (base.desc.fed$source)
base.desc.fed$stateYearFed <- factor (base.desc.fed$stateYearFed)
base.desc.fed$incGover <- factor (base.desc.fed$incGover)
summary (base.desc.fed); dim (base.desc.fed)


## Calculating vote share conditional on winning
round (mean (base.desc[base.desc$winPAN==1,]$shPAN, na.rm=T)*100,1); round (mean (base.desc.fed[base.desc.fed$firstPAN_fed==1,]$shPAN_fed, na.rm=T)*100,1)
round (mean (base.desc[base.desc$winPRD==1,]$shPRD, na.rm=T)*100,1); round (mean (base.desc.fed[base.desc.fed$firstPRD_fed==1,]$shPRD_fed, na.rm=T)*100,1)

# PAN
(descriptive.pan01 <- rbind (
  
  ## Dependent variables
  with (base.desc, c (mean (winPAN, na.rm=T), sd (winPAN, na.rm=T), min (winPAN, na.rm=T), max (winPAN, na.rm=T)))
  , with (base.desc, c (mean (shPAN, na.rm=T), sd (shPAN, na.rm=T), min (shPAN, na.rm=T), max (shPAN, na.rm=T)))
  , with (base.desc.fed, c (mean (firstPAN_fed, na.rm=T), sd (firstPAN_fed, na.rm=T), min (firstPAN_fed, na.rm=T), max (firstPAN_fed, na.rm=T)))
  , with (base.desc.fed, c (mean (shPAN_fed, na.rm=T), sd (shPAN_fed, na.rm=T), min (shPAN_fed, na.rm=T), max (shPAN_fed, na.rm=T)))
  
  ## Main explanatory variables
  , with (base.desc, c (mean (goverPAN, na.rm=T), sd (goverPAN, na.rm=T), min (goverPAN, na.rm=T), max (goverPAN, na.rm=T)))
  , with (base.desc, c (mean (incPAN_qrs, na.rm=T), sd (incPAN_qrs, na.rm=T), min (incPAN_qrs, na.rm=T), max (incPAN_qrs, na.rm=T)))
  
  ## Control variables
  , with (base.desc, c (mean (incPAN, na.rm=T), sd (incPAN, na.rm=T), min (incPAN, na.rm=T), max (incPAN, na.rm=T)))
  , with (base.desc, c (mean (shPAN_lag, na.rm=T), sd (shPAN_lag, na.rm=T), min (shPAN_lag, na.rm=T), max (shPAN_lag, na.rm=T)))
  , with (base.desc.fed, c (mean (firstPAN_fed_lag, na.rm=T), sd (firstPAN_fed_lag, na.rm=T), min (firstPAN_fed_lag, na.rm=T), max (firstPAN_fed_lag, na.rm=T)))
  , with (base.desc.fed, c (mean (shPAN_fed_lag, na.rm=T), sd (shPAN_fed_lag, na.rm=T), min (shPAN_fed_lag, na.rm=T), max (shPAN_fed_lag, na.rm=T)))
  , with (base.desc, c (mean (shPAN_qrs, na.rm=T), sd (shPAN_qrs, na.rm=T), min (shPAN_qrs, na.rm=T), max (shPAN_qrs, na.rm=T)))
  , with (base.desc, c (mean (alt, na.rm=T), sd (alt, na.rm=T), min (alt, na.rm=T), max (alt, na.rm=T)))
  , with (base.desc, c (mean (concGober, na.rm=T), sd (concGober, na.rm=T), min (concGober, na.rm=T), max (concGober, na.rm=T)))
  , with (base.desc, c (mean (split, na.rm=T), sd (split, na.rm=T), min (split, na.rm=T), max (split, na.rm=T)))
  ))

# PRD
(descriptive.prd01 <- rbind (
  
  ## Dependent variables
  with (base.desc, c (mean (winPRD, na.rm=T), sd (winPRD, na.rm=T), min (winPRD, na.rm=T), max (winPRD, na.rm=T)))
  , with (base.desc, c (mean (shPRD, na.rm=T), sd (shPRD, na.rm=T), min (shPRD, na.rm=T), max (shPRD, na.rm=T)))
  , with (base.desc.fed, c (mean (firstPRD_fed, na.rm=T), sd (firstPRD_fed, na.rm=T), min (firstPRD_fed, na.rm=T), max (firstPRD_fed, na.rm=T)))
  , with (base.desc.fed, c (mean (shPRD_fed, na.rm=T), sd (shPRD_fed, na.rm=T), min (shPRD_fed, na.rm=T), max (shPRD_fed, na.rm=T)))
  
  ## Main explanatory variables
  , rep (NA, 4)
  , with (base.desc, c (mean (incPRD_qrs, na.rm=T), sd (incPRD_qrs, na.rm=T), min (incPRD_qrs, na.rm=T), max (incPRD_qrs, na.rm=T)))
  
  ## Control variables
  , with (base.desc, c (mean (incPRD, na.rm=T), sd (incPRD, na.rm=T), min (incPRD, na.rm=T), max (incPRD, na.rm=T)))
  , with (base.desc, c (mean (shPRD_lag, na.rm=T), sd (shPRD_lag, na.rm=T), min (shPRD_lag, na.rm=T), max (shPRD_lag, na.rm=T)))
  , with (base.desc.fed, c (mean (firstPRD_fed_lag, na.rm=T), sd (firstPRD_fed_lag, na.rm=T), min (firstPRD_fed_lag, na.rm=T), max (firstPRD_fed_lag, na.rm=T)))
  , with (base.desc.fed, c (mean (shPRD_fed_lag, na.rm=T), sd (shPRD_fed_lag, na.rm=T), min (shPRD_fed_lag, na.rm=T), max (shPRD_fed_lag, na.rm=T)))
  , with (base.desc, c (mean (shPRD_qrs, na.rm=T), sd (shPRD_qrs, na.rm=T), min (shPRD_qrs, na.rm=T), max (shPRD_qrs, na.rm=T)))
  , with (base.desc, c (mean (alt, na.rm=T), sd (alt, na.rm=T), min (alt, na.rm=T), max (alt, na.rm=T)))
  , with (base.desc, c (mean (concGober, na.rm=T), sd (concGober, na.rm=T), min (concGober, na.rm=T), max (concGober, na.rm=T)))
  , with (base.desc, c (mean (split, na.rm=T), sd (split, na.rm=T), min (split, na.rm=T), max (split, na.rm=T)))
  ))

(descriptive <- cbind (descriptive.pan01, rep (NA, nrow (descriptive.pan01)), descriptive.prd01))

rows <- c ("Winner", "Vote share", "Winner (federal)", "Vote share (federal)"
           , "Copartisan governor", "Copartisan neighbors"
           , "Incumbency", "Previous vote", "Previous winner (federal)", "Previous vote (federal)"
           , "Vote neighbors", "Alternation", "Gubernatorial concurrent", "Split municipality")

Header1 <- paste ("\\toprule & \\multicolumn{4}{c}{\\textbf{(a) PAN (1984-2000)}} & & \\multicolumn{4}{c}{\\textbf{(b) PRD (1989-2000)}} \\\\ \\cmidrule{2-5} \\cmidrule{7-10} \n")
Header2 <- paste ("\\multicolumn{1}{l}{\\textbf{(a) Dependent variables}} & \\multicolumn{1}{c}{mean} & \\multicolumn{1}{c}{s.d.} & \\multicolumn{1}{c}{min.} & \\multicolumn{1}{c}{max.} & & \\multicolumn{1}{c}{mean} & \\multicolumn{1}{c}{s.d.} & \\multicolumn{1}{c}{min.} & \\multicolumn{1}{c}{max.} \\\\ \\midrule \n")
Header3 <- paste ("[2ex] \\multicolumn{10}{l}{\\textbf{(b) Explanatory variables}}  \\\\ \\midrule \n")
Header4 <- paste ("[2ex] \\multicolumn{10}{l}{\\textbf{(c) Control variables}} \\\\ \\midrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 4
addtorow$pos[[4]] <- 6
addtorow$command <- c (Header1, Header2, Header3, Header4)
print (xtable (  cbind (rows, round (descriptive, 2))
                 , align=c("l","l","r","r","r","r","r","r","r","r","r")
                 , digits=2
                 , caption="Descriptive statistics."
                 , label="T3:descriptive")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="small"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )




### Replicating Table 3
(tab.coefs.mex01a <- cbind (
  
  # Winner
  c (coef.Wpan.gov001a[1,1], rep (NA, 5), coef.Wpan.gov001a[2,1], NA)
  , c (NA, coef.Wpan.qrs002a[c (1,3,2,26:27,4),1], NA)
  , c (NA, coef.Wpan.qrs003a[1:2,1], rep (NA,3), coef.Wpan.qrs003a[3,1], NA)
  , rep (NA, 8)
  , c (NA, coef.Wprd.qrs002a[c (1,3,2,20:21,4),1], NA)
  , c (NA, coef.Wprd.qrs003a[1:2,1], rep (NA,3), coef.Wprd.qrs003a[3,1], NA)
  
  # Vote share
  , rep (NA, 8)
  , c (coef.Vpan.gov001a[1,1], rep (NA, 6), coef.Vpan.gov001a[2,1])
  , c (NA, coef.Vpan.qrs002a[c (1,3,2,26:27),1], NA, coef.Vpan.qrs002a[c (4),1])
  , c (NA, coef.Vpan.qrs003a[1:2,1], rep (NA,3), NA, coef.Vpan.qrs003a[3,1])
  , rep (NA, 8)
  , c (NA, coef.Vprd.qrs002a[c (1,3,2,20:21),1], NA, coef.Vprd.qrs002a[c (4),1])
  , c (NA, coef.Vprd.qrs003a[1:2,1], rep (NA,4), coef.Vprd.qrs003a[3,1])
))
(tab.ses.mex01a <- cbind (
  # Winner
  c (coef.Wpan.gov001a[1,2], rep (NA, 5), coef.Wpan.gov001a[2,2], NA)
  , c (NA, coef.Wpan.qrs002a[c (1,3,2,26:27,4),2], NA)
  , c (NA, coef.Wpan.qrs003a[1:2,2], rep (NA,3), coef.Wpan.qrs003a[3,2], NA)
  , rep (NA, 8)
  , c (NA, coef.Wprd.qrs002a[c (1,3,2,20:21,4),2], NA)
  , c (NA, coef.Wprd.qrs003a[1:2,2], rep (NA,3), coef.Wprd.qrs003a[3,2], NA)
  
  # Vote share
  , rep (NA, 8)
  , c (coef.Vpan.gov001a[1,2], rep (NA, 6), coef.Vpan.gov001a[2,2])
  , c (NA, coef.Vpan.qrs002a[c (1,3,2,26:27),2], NA, coef.Vpan.qrs002a[c (4),2])
  , c (NA, coef.Vpan.qrs003a[1:2,2], rep (NA,3), NA, coef.Vpan.qrs003a[3,2])
  , rep (NA, 8)
  , c (NA, coef.Vprd.qrs002a[c (1,3,2,20:21),2], NA, coef.Vprd.qrs002a[c (4),2])
  , c (NA, coef.Vprd.qrs003a[1:2,2], rep (NA,4), coef.Vprd.qrs003a[3,2])
  ))

# adding the asterisks
tab.coefs.mex01a2 <- matrix (sprintf ("%.2f", round (tab.coefs.mex01a, 3)), ncol=13)
tab.coefs.mex01a2 <- matrix (paste (tab.coefs.mex01a2, ifelse (is.na (tab.coefs.mex01a / tab.ses.mex01a), "", ifelse (abs (tab.coefs.mex01a / tab.ses.mex01a)>=abs(qnorm (0.025)), "**", ifelse (abs (tab.coefs.mex01a / tab.ses.mex01a)>=abs(qnorm (0.05)), "*", ""))), sep=""), ncol=13)
tab.ses.mex01a2 <- matrix (sprintf ("%.2f", round (tab.ses.mex01a, 3)), ncol=13)
tab.ses.mex01a2 <- matrix (paste ("(", tab.ses.mex01a2, ")", sep=""), ncol=13)

odd <- seq (1, nrow (tab.coefs.mex01a2)*2, by=2); even <- seq (2, nrow (tab.coefs.mex01a2)*2, by=2)
(tab.results.mex01a <- rbind (tab.coefs.mex01a2, tab.ses.mex01a2))
rownames (tab.results.mex01a) <- c (odd, even)
tab.results.mex01a <- tab.results.mex01a[order (as.numeric (rownames (tab.results.mex01a))),]
tab.results.mex01a <- ifelse (tab.results.mex01a=="NA" | tab.results.mex01a=="(NA)", "", tab.results.mex01a)

rows <- c ("Copartisan", "~~~~~governor", "Copartisan", "~~~~~neighbors", "Vote neighbors", "", "Alternation", "", "Cop. neighbors", "~~~~~$\\times$ Alternation", "Vote neighbors", "~~~~~$\\times$ Alternation", "Previous vote", "", "Incumbency", "")

(Ns <- cbind (unlist (pdim (Wpan.gov001a)$nT), unlist (pdim (Wpan.qrs002a)$nT), unlist (pdim (Wpan.qrs003a)$nT), unlist (pdim (Wprd.qrs002a)$nT), unlist (pdim (Wprd.qrs003a)$nT), unlist (pdim (Vpan.gov001a)$nT), unlist (pdim (Vpan.qrs002a)$nT), unlist (pdim (Vpan.qrs003a)$nT), unlist (pdim (Vprd.qrs002a)$nT), unlist (pdim (Vprd.qrs003a)$nT)))
(rsq <- cbind (sum.Wpan.gov001a$r.squared, sum.Wpan.qrs002a$r.squared, sum.Wpan.qrs003a$r.squared, sum.Wprd.qrs002a$r.squared, sum.Wprd.qrs003a$r.squared, sum.Vpan.gov001a$r.squared, sum.Vpan.qrs002a$r.squared, sum.Vpan.qrs003a$r.squared, sum.Vprd.qrs002a$r.squared, sum.Vprd.qrs003a$r.squared))

Header1 <- paste ("\\toprule & \\multicolumn{6}{c}{\\textbf{(a) Outcome: \\emph{Winner}}} & & \\multicolumn{6}{c}{\\textbf{(b) Outcome: \\emph{Vote share}}} \\\\ \\cmidrule{2-7} \\cmidrule{9-14} \n")
Header2 <- paste ("& \\multicolumn{3}{c}{PAN} & & \\multicolumn{2}{c}{PRD} & & \\multicolumn{3}{c}{PAN} & & \\multicolumn{2}{c}{PRD} \\\\ \\cmidrule{2-4} \\cmidrule{6-7} \\cmidrule{9-11} \\cmidrule{13-14} \n")
Header3 <- paste (" & \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & & \\multicolumn{1}{c}{(9)} & \\multicolumn{1}{c}{(10)} \\\\ \\midrule \n")
add.rsq01 <- paste ("\\midrule $R^2$ & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,5],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,8],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,9],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,10],2)), "} \\\\ \n")
add.rsq02 <- paste ("adj. $R^2$ & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,5],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,8],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,9],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,10],2)), "} \\\\ [1ex] \n")
add.nmunis01 <- paste ("\\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,5],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,8],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,9],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,10],2)), "} \\\\ \n")
add.ntime01 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,5],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,8],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,9],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,10],2)), "} \\\\ \n")
add.nobs01 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,5],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,8],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,9],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,10],2)), "} \\\\ \\bottomrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 16
addtorow$pos[[5]] <- 16
addtorow$pos[[6]] <- 16
addtorow$pos[[7]] <- 16
addtorow$pos[[8]] <- 16
addtorow$command <- c (Header1, Header2, Header3
                       , add.rsq01, add.rsq02
                       , add.nmunis01, add.ntime01, add.nobs01)
print (xtable (  cbind (rows, tab.results.mex01a)
                 , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c")
                 , caption="Diffusion effects in mayoral elections in Mexico, 1984-2000."
                 , label="T3:results01")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="small"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )




### Replicating Table 4
(tab.coefs.mex02a <- cbind (
  
  # Winner
  c (coef.Wpan.fed.gov001a[1,1], rep (NA, 5), coef.Wpan.fed.gov001a[2,1], NA)
  , c (NA, coef.Wpan.fed.qrs002a[c (1,3,2,11:12,4),1], NA)
  , c (NA, coef.Wpan.fed.qrs003a[1:2,1], rep (NA,3), coef.Wpan.fed.qrs003a[3,1], NA)
  , rep (NA, 8)
  , c (coef.Wprd.fed.gov001a[1,1], rep (NA, 5), coef.Wprd.fed.gov001a[2,1], NA)
  , c (NA, coef.Wprd.fed.qrs002a[c (1,3,2,11:12,4),1], NA)
  , c (NA, coef.Wprd.fed.qrs003a[1:2,1], rep (NA,3), coef.Wprd.fed.qrs003a[3,1], NA)
  
  # Vote share
  , rep (NA, 8)
  , c (coef.Vpan.fed.gov001a[1,1], rep (NA, 6), coef.Vpan.fed.gov001a[2,1])
  , c (NA, coef.Vpan.fed.qrs002a[c (1,3,2,11:12),1], NA, coef.Vpan.fed.qrs002a[c (4),1])
  , c (NA, coef.Vpan.fed.qrs003a[1:2,1], rep (NA,3), NA, coef.Vpan.fed.qrs003a[3,1])
  , rep (NA, 8)
  , c (coef.Vprd.fed.gov001a[1,1], rep (NA, 6), coef.Vprd.fed.gov001a[2,1])
  , c (NA, coef.Vprd.fed.qrs002a[c (1,3,2,11:12),1], NA, coef.Vprd.fed.qrs002a[c (4),1])
  , c (NA, coef.Vprd.fed.qrs003a[1:2,1], rep (NA,4), coef.Vprd.fed.qrs003a[3,1])
))
(tab.ses.mex02a <- cbind (
  
  # Winner
  c (coef.Wpan.fed.gov001a[1,2], rep (NA, 5), coef.Wpan.fed.gov001a[2,2], NA)
  , c (NA, coef.Wpan.fed.qrs002a[c (1,3,2,11:12,4),2], NA)
  , c (NA, coef.Wpan.fed.qrs003a[1:2,2], rep (NA,3), coef.Wpan.fed.qrs003a[3,2], NA)
  , rep (NA, 8)
  , c (coef.Wprd.fed.gov001a[1,2], rep (NA, 5), coef.Wprd.fed.gov001a[2,2], NA)
  , c (NA, coef.Wprd.fed.qrs002a[c (1,3,2,11:12,4),2], NA)
  , c (NA, coef.Wprd.fed.qrs003a[1:2,2], rep (NA,3), coef.Wprd.fed.qrs003a[3,2], NA)
  
  # Vote share
  , rep (NA, 8)
  , c (coef.Vpan.fed.gov001a[1,2], rep (NA, 6), coef.Vpan.fed.gov001a[2,2])
  , c (NA, coef.Vpan.fed.qrs002a[c (1,3,2,11:12),2], NA, coef.Vpan.fed.qrs002a[c (4),2])
  , c (NA, coef.Vpan.fed.qrs003a[1:2,2], rep (NA,3), NA, coef.Vpan.fed.qrs003a[3,2])
  , rep (NA, 8)
  , c (coef.Vprd.fed.gov001a[1,2], rep (NA, 6), coef.Vprd.fed.gov001a[2,2])
  , c (NA, coef.Vprd.fed.qrs002a[c (1,3,2,11:12),2], NA, coef.Vprd.fed.qrs002a[c (4),2])
  , c (NA, coef.Vprd.fed.qrs003a[1:2,2], rep (NA,4), coef.Vprd.fed.qrs003a[3,2])
  ))

# adding the asterisks
tab.coefs.mex02a2 <- matrix (sprintf ("%.2f", round (tab.coefs.mex02a, 3)), ncol=15)
tab.coefs.mex02a2 <- matrix (paste (tab.coefs.mex02a2, ifelse (is.na (tab.coefs.mex02a / tab.ses.mex02a), "", ifelse (abs (tab.coefs.mex02a / tab.ses.mex02a)>=abs(qnorm (0.025)), "**", ifelse (abs (tab.coefs.mex02a / tab.ses.mex02a)>=abs(qnorm (0.05)), "*", ""))), sep=""), ncol=15)
tab.ses.mex02a2 <- matrix (sprintf ("%.2f", round (tab.ses.mex02a, 3)), ncol=15)
tab.ses.mex02a2 <- matrix (paste ("(", tab.ses.mex02a2, ")", sep=""), ncol=15)

odd <- seq (1, nrow (tab.coefs.mex02a2)*2, by=2); even <- seq (2, nrow (tab.coefs.mex02a2)*2, by=2)
(tab.results.mex02a <- rbind (tab.coefs.mex02a2, tab.ses.mex02a2))
rownames (tab.results.mex02a) <- c (odd, even)
tab.results.mex02a <- tab.results.mex02a[order (as.numeric (rownames (tab.results.mex02a))),]
tab.results.mex02a <- ifelse (tab.results.mex02a=="NA" | tab.results.mex02a=="(NA)", "", tab.results.mex02a)

rows <- c ("Copartisan", "~~~~~governor", "Copartisan", "~~~~~neighbors", "Vote neighbors", "", "Alternation", "", "Cop. neighbors", "~~~~~$\\times$ Alternation", "Vote neighbors", "~~~~~$\\times$ Alternation", "Previous vote", "", "Incumbency", "")

(Ns <- cbind (unlist (pdim (Wpan.fed.gov001a)$nT), unlist (pdim (Wpan.fed.qrs002a)$nT), unlist (pdim (Wpan.fed.qrs003a)$nT), unlist (pdim (Wprd.fed.gov001a)$nT), unlist (pdim (Wprd.fed.qrs002a)$nT), unlist (pdim (Wprd.fed.qrs003a)$nT), unlist (pdim (Vpan.fed.gov001a)$nT), unlist (pdim (Vpan.fed.qrs002a)$nT), unlist (pdim (Vpan.fed.qrs003a)$nT), unlist (pdim (Vprd.fed.gov001a)$nT), unlist (pdim (Vprd.fed.qrs002a)$nT), unlist (pdim (Vprd.fed.qrs003a)$nT)))
(rsq <- cbind (sum.Wpan.fed.gov001a$r.squared, sum.Wpan.fed.qrs002a$r.squared, sum.Wpan.fed.qrs003a$r.squared, sum.Wprd.fed.gov001a$r.squared, sum.Wprd.fed.qrs002a$r.squared, sum.Wprd.fed.qrs003a$r.squared, sum.Vpan.fed.gov001a$r.squared, sum.Vpan.fed.qrs002a$r.squared, sum.Vpan.fed.qrs003a$r.squared, sum.Vprd.fed.gov001a$r.squared, sum.Vprd.fed.qrs002a$r.squared, sum.Vprd.fed.qrs003a$r.squared))

Header1 <- paste ("\\toprule & \\multicolumn{7}{c}{\\textbf{(a) Outcome: \\emph{Winner (federal)}}} & & \\multicolumn{7}{c}{\\textbf{(b) Outcome: \\emph{Vote share (federal)}}} \\\\ \\cmidrule{2-8} \\cmidrule{10-16} \n")
Header2 <- paste ("& \\multicolumn{3}{c}{PAN} & & \\multicolumn{3}{c}{PRD} & & \\multicolumn{3}{c}{PAN} & & \\multicolumn{3}{c}{PRD} \\\\ \\cmidrule{2-4} \\cmidrule{6-8} \\cmidrule{10-12} \\cmidrule{14-16} \n")
Header3 <- paste (" & \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} & \\multicolumn{1}{c}{(9)} & & \\multicolumn{1}{c}{(10)} & \\multicolumn{1}{c}{(11)} & \\multicolumn{1}{c}{(12)} \\\\ \\midrule \n")
add.rsq01 <- paste ("\\midrule $R^2$ & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,6],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,8],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,9],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,10],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,11],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[1,12],2)), "} \\\\ \n")
add.rsq02 <- paste ("adj. $R^2$ & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,6],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,8],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,9],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,10],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,11],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.2f", round (rsq[2,12],2)), "} \\\\ [1ex] \n")
add.nmunis01 <- paste ("\\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,6],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,8],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,9],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,10],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,11],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[1,12],2)), "} \\\\ \n")
add.ntime01 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,6],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,8],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,9],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,10],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,11],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[2,12],2)), "} \\\\ \n")
add.nobs01 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,3],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,6],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,8],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,9],2)), "} & & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,10],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,11],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns[3,12],2)), "} \\\\ \\bottomrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 16
addtorow$pos[[5]] <- 16
addtorow$pos[[6]] <- 16
addtorow$pos[[7]] <- 16
addtorow$pos[[8]] <- 16
addtorow$command <- c (Header1, Header2, Header3
                       , add.rsq01, add.rsq02
                       , add.nmunis01, add.ntime01, add.nobs01)
print (xtable (  cbind (rows, tab.results.mex02a)
                 , align=c("l","l","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c")
                 , caption="Diffusion effects in federal elections in Mexico, 1994-2000."
                 , label="T3:results02")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="small"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )




### Replicating Table A1
(tab.coefs.mex01b <- rbind (
  
  ## PAN
  c (coef.Wpan.gov001a[1,1], coef.Wpan.gov001b[1,1], NA, NA, NA, coef.Wpan.gov001e[2,1], coef.Wpan.gov001f[1,1], coef.Wpan.gov001g[1,1])
  , c (coef.Wpan.qrs002a[1,1], coef.Wpan.qrs002b[1,1], coef.Wpan.nkrs002a[1,1], coef.Wpan.smdrs002h[1,1], coef.Wpan.qrs002c[1,1], coef.Wpan.qrs002e[2,1], coef.Wpan.qrs002f[1,1], coef.Wpan.qrs002g[1,1])
  , c (coef.Vpan.gov001a[1,1], coef.Vpan.gov001b[1,1], NA, NA, NA, coef.Vpan.gov001e[2,1], coef.Vpan.gov001f[1,1], coef.Vpan.gov001g[1,1])
  , c (coef.Vpan.qrs002a[1,1], coef.Vpan.qrs002b[1,1], coef.Vpan.nkrs002a[1,1], coef.Vpan.smdrs002h[1,1], coef.Vpan.qrs002c[1,1], coef.Vpan.qrs002e[2,1], coef.Vpan.qrs002f[1,1], coef.Vpan.qrs002g[1,1])
  
  ## PRD
  , c (coef.Wprd.qrs002a[1,1], coef.Wprd.qrs002b[1,1], coef.Wprd.nkrs002a[1,1], coef.Wprd.smdrs002h[1,1], coef.Wprd.qrs002c[1,1], coef.Wprd.qrs002e[2,1], coef.Wprd.qrs002f[1,1], coef.Wprd.qrs002g[1,1])
  , c (coef.Vprd.qrs002a[1,1], coef.Vprd.qrs002b[1,1], coef.Vprd.nkrs002a[1,1], coef.Vprd.smdrs002h[1,1], coef.Vprd.qrs002c[1,1], coef.Vprd.qrs002e[2,1], coef.Vprd.qrs002f[1,1], coef.Vprd.qrs002g[1,1])
))
(tab.ses.mex01b <- rbind (
  
  ## PAN
  c (coef.Wpan.gov001a[1,2], coef.Wpan.gov001b[1,2], NA, NA, NA, coef.Wpan.gov001e[2,2], coef.Wpan.gov001f[1,2], coef.Wpan.gov001g[1,2])
  , c (coef.Wpan.qrs002a[1,2], coef.Wpan.qrs002b[1,2], coef.Wpan.nkrs002a[1,2], coef.Wpan.smdrs002h[1,2], coef.Wpan.qrs002c[1,2], coef.Wpan.qrs002e[2,2], coef.Wpan.qrs002f[1,2], coef.Wpan.qrs002g[1,2])
  , c (coef.Vpan.gov001a[1,2], coef.Vpan.gov001b[1,2], NA, NA, NA, coef.Vpan.gov001e[2,2], coef.Vpan.gov001f[1,2], coef.Vpan.gov001g[1,2])
  , c (coef.Vpan.qrs002a[1,2], coef.Vpan.qrs002b[1,2], coef.Vpan.nkrs002a[1,2], coef.Vpan.smdrs002h[1,2], coef.Vpan.qrs002c[1,2], coef.Vpan.qrs002e[2,2], coef.Vpan.qrs002f[1,2], coef.Vpan.qrs002g[1,2])
  
  ## PRD
  , c (coef.Wprd.qrs002a[1,2], coef.Wprd.qrs002b[1,2], coef.Wprd.nkrs002a[1,2], coef.Wprd.smdrs002h[1,2], coef.Wprd.qrs002c[1,2], coef.Wprd.qrs002e[2,2], coef.Wprd.qrs002f[1,2], coef.Wprd.qrs002g[1,2])
  , c (coef.Vprd.qrs002a[1,2], coef.Vprd.qrs002b[1,2], coef.Vprd.nkrs002a[1,2], coef.Vprd.smdrs002h[1,2], coef.Vprd.qrs002c[1,2], coef.Vprd.qrs002e[2,2], coef.Vprd.qrs002f[1,2], coef.Vprd.qrs002g[1,2])
  ))

# adding the asterisks
tab.coefs.mex01b2 <- matrix (sprintf ("%.2f", round (tab.coefs.mex01b, 3)), ncol=8)
tab.coefs.mex01b2 <- matrix (paste (tab.coefs.mex01b2, ifelse (is.na (tab.coefs.mex01b / tab.ses.mex01b), "", ifelse (abs (tab.coefs.mex01b / tab.ses.mex01b)>=abs(qnorm (0.025)), "**", ifelse (abs (tab.coefs.mex01b / tab.ses.mex01b)>=abs(qnorm (0.05)), "*", ""))), sep=""), ncol=8)
tab.ses.mex01b2 <- matrix (sprintf ("%.2f", round (tab.ses.mex01b, 3)), ncol=8)
tab.ses.mex01b2 <- matrix (paste ("(", tab.ses.mex01b2, ")", sep=""), ncol=8)

odd <- seq (1, nrow (tab.coefs.mex01b2)*2, by=2); even <- seq (2, nrow (tab.coefs.mex01b2)*2, by=2)
(tab.results.mex01b <- rbind (tab.coefs.mex01b2, tab.ses.mex01b2))
rownames (tab.results.mex01b) <- c (odd, even)
tab.results.mex01b <- tab.results.mex01b[order (as.numeric (rownames (tab.results.mex01b))),]
tab.results.mex01b <- ifelse (tab.results.mex01b=="NA" | tab.results.mex01b=="(NA)", "", tab.results.mex01b)

rows <- c ("Copartisan governor", "", "Copartisan neighbors", ""
           , "Copartisan governor", "", "Copartisan neighbors", ""
           , "Copartisan neighbors", "", "Copartisan neighbors", "")

(Ns01 <- cbind (unlist (pdim (Wpan.qrs002a)$nT), unlist (pdim (Wpan.qrs002b)$nT), unlist (pdim (Wpan.nkrs002a)$nT), unlist (pdim (Wpan.smdrs002h)$nT), unlist (pdim (Wpan.qrs002c)$nT), unlist (pdim (Wpan.qrs002e)$nT), unlist (pdim (Wpan.qrs002f)$nT), unlist (pdim (Wpan.qrs002g)$nT)))
(Ns02 <- cbind (unlist (pdim (Wprd.qrs002a)$nT), unlist (pdim (Wprd.qrs002b)$nT), unlist (pdim (Wprd.nkrs002a)$nT), unlist (pdim (Wprd.smdrs002h)$nT), unlist (pdim (Wprd.qrs002c)$nT), unlist (pdim (Wprd.qrs002e)$nT), unlist (pdim (Wprd.qrs002f)$nT), unlist (pdim (Wprd.qrs002g)$nT)))

Header0 <- paste (" \\multicolumn{9}{l}{} \\\\ \n")
Header1 <- paste ("\\toprule & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{add.} & \\multicolumn{1}{c}{nearest-$k$} & \\multicolumn{1}{c}{SMD} & \\multicolumn{1}{c}{neighbor} & \\multicolumn{1}{c}{lagged} & \\multicolumn{1}{c}{incl.} & \\multicolumn{1}{c}{excl.} \\\\ \n")
Header2 <- paste ("& \\multicolumn{1}{c}{Table 3} & \\multicolumn{1}{c}{controls} & \\multicolumn{1}{c}{neighbors} & \\multicolumn{1}{c}{neighbors} & \\multicolumn{1}{c}{dummy} & \\multicolumn{1}{c}{DV} & \\multicolumn{1}{c}{alliances} & \\multicolumn{1}{c}{Oaxaca} \\\\ \\cmidrule{2-9} \n")
Header3 <- paste (" \\multicolumn{1}{l}{\\textbf{(a) PAN (\\emph{Winner})}} & \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} \\\\ \\midrule \n")
Header4 <- paste ("[2ex] \\multicolumn{9}{l}{\\textbf{(b) PAN (\\emph{Vote share})}} \\\\ \\midrule \n")
Header5 <- paste (" \\multicolumn{9}{l}{\\textbf{(c) PRD (\\emph{Winner})}} \\\\ \\midrule \n")
Header6 <- paste (" \\multicolumn{9}{l}{\\textbf{(d) PRD (\\emph{Vote share})}} \\\\ \\midrule \n")

add.nmunis01 <- paste ("\\midrule \\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,8],2)), "} \\\\ \n")
add.nmunis02 <- paste ("\\midrule \\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,8],2)), "} \\\\ \n")
add.ntime01 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,8],2)), "} \\\\ \n")
add.ntime02 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,8],2)), "} \\\\ \n")
add.nobs01 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,8],2)), "} \\\\ \\midrule \n")
add.nobs02 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,8],2)), "} \\\\ \\midrule \n")
add.fe <- paste ("\\multicolumn{1}{l}{municipality FE} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} \\\\ \n")
add.year <- paste ("\\multicolumn{1}{l}{year FE} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} \\\\ \\bottomrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 4
addtorow$pos[[5]] <- 8
addtorow$pos[[6]] <- 8
addtorow$pos[[7]] <- 8
addtorow$pos[[8]] <- 8
addtorow$pos[[9]] <- 8
addtorow$pos[[10]] <- 10
addtorow$pos[[11]] <- 12
addtorow$pos[[12]] <- 12
addtorow$pos[[13]] <- 12
addtorow$pos[[14]] <- 12
addtorow$pos[[15]] <- 12
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , add.nmunis01, add.ntime01, add.nobs01
                       , Header0, Header5, Header6
                       , add.nmunis02, add.ntime02, add.nobs02
                       , add.fe, add.year)
print (xtable (  cbind (rows, tab.results.mex01b)
                 , align=c("l","l","c","c","c","c","c","c","c","c")
                 , caption="Robustness checks (1): Mayoral elections."
                 , label="T3:robustness01")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )





### Replicating Table A2
(tab.coefs.mex02b <- rbind (
  
  ## PAN
  c (coef.Wpan.fed.gov001a[1,1], coef.Wpan.fed.gov001b[1,1], NA, NA, NA, coef.Wpan.fed.gov001e[2,1], NA, coef.Wpan.fed.gov001g[1,1])
  , c (coef.Wpan.fed.qrs002a[1,1], coef.Wpan.fed.qrs002b[1,1], coef.Wpan.fed.nkrs002a[1,1], coef.Wpan.fed.smdrs002a[1,1], coef.Wpan.fed.qrs002c[1,1], coef.Wpan.fed.qrs002e[2,1], coef.Wpan.fed.qrs002f[1,1], coef.Wpan.fed.qrs002g[1,1])
  , c (coef.Vpan.fed.gov001a[1,1], coef.Vpan.fed.gov001b[1,1], NA, NA, NA, coef.Vpan.fed.gov001e[2,1], NA, coef.Vpan.fed.gov001g[1,1])
  , c (coef.Vpan.fed.qrs002a[1,1], coef.Vpan.fed.qrs002b[1,1], coef.Vpan.fed.nkrs002a[1,1], coef.Vpan.fed.smdrs002a[1,1], coef.Vpan.fed.qrs002c[1,1], coef.Vpan.fed.qrs002e[2,1], coef.Vpan.fed.qrs002f[1,1], coef.Vpan.fed.qrs002g[1,1])
  
  ## PRD
  , c (coef.Wprd.fed.gov001a[1,1], coef.Wprd.fed.gov001b[1,1], NA, NA, NA, coef.Wprd.fed.gov001e[2,1], NA, coef.Wprd.fed.gov001g[1,1])
  , c (coef.Wprd.fed.qrs002a[1,1], coef.Wprd.fed.qrs002b[1,1], coef.Wprd.fed.nkrs002a[1,1], coef.Wprd.fed.smdrs002a[1,1], coef.Wprd.fed.qrs002c[1,1], coef.Wprd.fed.qrs002e[2,1], coef.Wprd.fed.qrs002f[1,1], coef.Wprd.fed.qrs002g[1,1])
  , c (coef.Vprd.fed.gov001a[1,1], coef.Vprd.fed.gov001b[1,1], NA, NA, NA, coef.Vprd.fed.gov001e[2,1], NA, coef.Vprd.fed.gov001g[1,1])
  , c (coef.Vprd.fed.qrs002a[1,1], coef.Vprd.fed.qrs002b[1,1], coef.Vprd.fed.nkrs002a[1,1], coef.Vprd.fed.smdrs002a[1,1], coef.Vprd.fed.qrs002c[1,1], coef.Vprd.fed.qrs002e[2,1], coef.Vprd.fed.qrs002f[1,1], coef.Vprd.fed.qrs002g[1,1])
  ))
(tab.ses.mex02b <- rbind (
  
  ## PAN
  c (coef.Wpan.fed.gov001a[1,2], coef.Wpan.fed.gov001b[1,2], NA, NA, NA, coef.Wpan.fed.gov001e[2,2], NA, coef.Wpan.fed.gov001g[1,2])
  , c (coef.Wpan.fed.qrs002a[1,2], coef.Wpan.fed.qrs002b[1,2], coef.Wpan.fed.nkrs002a[1,2], coef.Wpan.fed.smdrs002a[1,2], coef.Wpan.fed.qrs002c[1,2], coef.Wpan.fed.qrs002e[2,2], coef.Wpan.fed.qrs002f[1,2], coef.Wpan.fed.qrs002g[1,2])
  , c (coef.Vpan.fed.gov001a[1,2], coef.Vpan.fed.gov001b[1,2], NA, NA, NA, coef.Vpan.fed.gov001e[2,2], NA, coef.Vpan.fed.gov001g[1,2])
  , c (coef.Vpan.fed.qrs002a[1,2], coef.Vpan.fed.qrs002b[1,2], coef.Vpan.fed.nkrs002a[1,2], coef.Vpan.fed.smdrs002a[1,2], coef.Vpan.fed.qrs002c[1,2], coef.Vpan.fed.qrs002e[2,2], coef.Vpan.fed.qrs002f[1,2], coef.Vpan.fed.qrs002g[1,2])
  
  ## PRD
  , c (coef.Wprd.fed.gov001a[1,2], coef.Wprd.fed.gov001b[1,2], NA, NA, NA, coef.Wprd.fed.gov001e[2,2], NA, coef.Wprd.fed.gov001g[1,2])
  , c (coef.Wprd.fed.qrs002a[1,2], coef.Wprd.fed.qrs002b[1,2], coef.Wprd.fed.nkrs002a[1,2], coef.Wprd.fed.smdrs002a[1,2], coef.Wprd.fed.qrs002c[1,2], coef.Wprd.fed.qrs002e[2,2], coef.Wprd.fed.qrs002f[1,2], coef.Wprd.fed.qrs002g[1,2])
  , c (coef.Vprd.fed.gov001a[1,2], coef.Vprd.fed.gov001b[1,2], NA, NA, NA, coef.Vprd.fed.gov001e[2,2], NA, coef.Vprd.fed.gov001g[1,2])
  , c (coef.Vprd.fed.qrs002a[1,2], coef.Vprd.fed.qrs002b[1,2], coef.Vprd.fed.nkrs002a[1,2], coef.Vprd.fed.smdrs002a[1,2], coef.Vprd.fed.qrs002c[1,2], coef.Vprd.fed.qrs002e[2,2], coef.Vprd.fed.qrs002f[1,2], coef.Vprd.fed.qrs002g[1,2])
  ))

# adding the asterisks
tab.coefs.mex02b2 <- matrix (sprintf ("%.2f", round (tab.coefs.mex02b, 3)), ncol=8)
tab.coefs.mex02b2 <- matrix (paste (tab.coefs.mex02b2, ifelse (is.na (tab.coefs.mex02b / tab.ses.mex02b), "", ifelse (abs (tab.coefs.mex02b / tab.ses.mex02b)>=abs(qnorm (0.025)), "**", ifelse (abs (tab.coefs.mex02b / tab.ses.mex02b)>=abs(qnorm (0.05)), "*", ""))), sep=""), ncol=8)
tab.ses.mex02b2 <- matrix (sprintf ("%.2f", round (tab.ses.mex02b, 3)), ncol=8)
tab.ses.mex02b2 <- matrix (paste ("(", tab.ses.mex02b2, ")", sep=""), ncol=8)

odd <- seq (1, nrow (tab.coefs.mex02b2)*2, by=2); even <- seq (2, nrow (tab.coefs.mex02b2)*2, by=2)
(tab.results.mex02b <- rbind (tab.coefs.mex02b2, tab.ses.mex02b2))
rownames (tab.results.mex02b) <- c (odd, even)
tab.results.mex02b <- tab.results.mex02b[order (as.numeric (rownames (tab.results.mex02b))),]
tab.results.mex02b <- ifelse (tab.results.mex02b=="NA" | tab.results.mex02b=="(NA)", "", tab.results.mex02b)

rows <- c ("Copartisan governor", "", "Copartisan neighbors", ""
           , "Copartisan governor", "", "Copartisan neighbors", ""
           , "Copartisan governor", "", "Copartisan neighbors", ""
           , "Copartisan neighbors", "", "Copartisan neighbors", "")

(Ns01 <- cbind (unlist (pdim (Wpan.fed.qrs002a)$nT), unlist (pdim (Wpan.fed.qrs002b)$nT), unlist (pdim (Wpan.fed.nkrs002a)$nT), unlist (pdim (Wpan.fed.smdrs002a)$nT), unlist (pdim (Wpan.fed.qrs002c)$nT), unlist (pdim (Wpan.fed.qrs002e)$nT), unlist (pdim (Wpan.fed.qrs002f)$nT), unlist (pdim (Wpan.fed.qrs002g)$nT)))
(Ns02 <- cbind (unlist (pdim (Wprd.fed.qrs002a)$nT), unlist (pdim (Wprd.fed.qrs002b)$nT), unlist (pdim (Wprd.fed.nkrs002a)$nT), unlist (pdim (Wprd.fed.smdrs002a)$nT), unlist (pdim (Wprd.fed.qrs002c)$nT), unlist (pdim (Wprd.fed.qrs002e)$nT), unlist (pdim (Wprd.fed.qrs002f)$nT), unlist (pdim (Wprd.fed.qrs002g)$nT)))

Header0 <- paste (" \\multicolumn{9}{l}{} \\\\ \n")
Header1 <- paste ("\\toprule & \\multicolumn{1}{c}{} & \\multicolumn{1}{c}{add.} & \\multicolumn{1}{c}{nearest-$k$} & \\multicolumn{1}{c}{SMD} & \\multicolumn{1}{c}{neighbor} & \\multicolumn{1}{c}{lagged} & \\multicolumn{1}{c}{incl.} & \\multicolumn{1}{c}{excl.} \\\\ \n")
Header2 <- paste ("& \\multicolumn{1}{c}{Table 4} & \\multicolumn{1}{c}{controls} & \\multicolumn{1}{c}{neighbors} & \\multicolumn{1}{c}{neighbors} & \\multicolumn{1}{c}{dummy} & \\multicolumn{1}{c}{DV} & \\multicolumn{1}{c}{alliances} & \\multicolumn{1}{c}{Oaxaca} \\\\ \\cmidrule{2-9} \n")
Header3 <- paste (" \\multicolumn{1}{l}{\\textbf{(a) PAN (\\emph{Winner})}} & \\multicolumn{1}{c}{(1)} & \\multicolumn{1}{c}{(2)} & \\multicolumn{1}{c}{(3)} & \\multicolumn{1}{c}{(4)} & \\multicolumn{1}{c}{(5)} & \\multicolumn{1}{c}{(6)} & \\multicolumn{1}{c}{(7)} & \\multicolumn{1}{c}{(8)} \\\\ \\midrule \n")
Header4 <- paste ("[2ex] \\multicolumn{9}{l}{\\textbf{(b) PAN (\\emph{Vote share})}} \\\\ \\midrule \n")
Header5 <- paste (" \\multicolumn{9}{l}{\\textbf{(c) PRD (\\emph{Winner})}} \\\\ \\midrule \n")
Header6 <- paste (" \\multicolumn{9}{l}{\\textbf{(d) PRD (\\emph{Vote share})}} \\\\ \\midrule \n")

add.nmunis01 <- paste ("\\midrule \\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[1,8],2)), "} \\\\ \n")
add.nmunis02 <- paste ("\\midrule \\# municipalities & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[1,8],2)), "} \\\\ \n")
add.ntime01 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[2,8],2)), "} \\\\ \n")
add.ntime02 <- paste ("\\# elections & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[2,8],2)), "} \\\\ \n")
add.nobs01 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns01[3,8],2)), "} \\\\ \\midrule \n")
add.nobs02 <- paste ("\\# observations & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,1],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,2],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,3],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,4],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,5],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,6],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,7],2)), "} & \\multicolumn{1}{c}{", sprintf ("%.0f", round (Ns02[3,8],2)), "} \\\\ \\midrule \n")
add.fe <- paste ("\\multicolumn{1}{l}{municipality FE} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{no} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} \\\\ \n")
add.year <- paste ("\\multicolumn{1}{l}{year FE} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} & \\multicolumn{1}{c}{yes} \\\\ \\bottomrule \n")

addtorow <- list ()
addtorow$pos <- list ()
addtorow$pos[[1]] <- 0
addtorow$pos[[2]] <- 0
addtorow$pos[[3]] <- 0
addtorow$pos[[4]] <- 4
addtorow$pos[[5]] <- 8
addtorow$pos[[6]] <- 8
addtorow$pos[[7]] <- 8
addtorow$pos[[8]] <- 8
addtorow$pos[[9]] <- 8
addtorow$pos[[10]] <- 12
addtorow$pos[[11]] <- 16
addtorow$pos[[12]] <- 16
addtorow$pos[[13]] <- 16
addtorow$pos[[14]] <- 16
addtorow$pos[[15]] <- 16
addtorow$command <- c (Header1, Header2, Header3, Header4
                       , add.nmunis01, add.ntime01, add.nobs01
                       , Header0, Header5, Header6
                       , add.nmunis02, add.ntime02, add.nobs02
                       , add.fe, add.year)
print (xtable (  cbind (rows, tab.results.mex02b)
                 , align=c("l","l","c","c","c","c","c","c","c","c")
                 , caption="Robustness checks (2): Federal elections."
                 , label="T3:robustness02")
       , sanitize.text.function=function(x){x}
       , floating=TRUE
       , table.placement="t"
       , caption.placement="top" 
       , latex.environments="center"
       , size="footnotesize"
       , include.colnames=FALSE
       , include.rownames=FALSE
       , hline.after = c ()
       , add.to.row=addtorow  )
